home *** CD-ROM | disk | FTP | other *** search
- {.PO 10}
-
- {$M 65520,16384,655360} { Lots of Stack for Recursion, Lots of Heap for ID tree }
-
- PROGRAM XRefForTurboOrMicrosoftPascal;
-
- {$I XREF.DOC} (* READ THE DOCUMENTATION *)
-
- USES
- CRT, DML, HEAPTREE;
-
- CONST
- Ver = '1.00';
- IncCount : WORD = 0;
-
- VAR
- FileDateAndTime : STRING;
- MainFileDateAndTime : STRING;
- Today : STRING;
- Footing : STRING;
- Heading : STRING;
- Margin : INTEGER; { set by .PO }
- LangType : BYTE;
- ExitSave : POINTER;
-
- CONST
- MaxIds = 1000;
- MaxIdLen = 30;
- ff = ^L;
- Sec = 64;
- RecLen = 128;
- MaxSec = Sec*RecLen;
- NumLen = 7; { Xref line # field width }
-
- TYPE
- FileType = file;
- IdStgType = String [MaxIdLen];
- InStgType = array [1..MaxSec] of char;
- CharSet = set of char;
- DTstgType = string [18];
-
- NodeType = ^NodeRecord;
-
- NodeRecord = Record
- Data : integer;
- Next : NodeType;
- end;
-
- FNRec = Record
- Last : NodeType;
- Next : NodeType;
- end;
-
- FirstNodeType = array [1..MaxIds] of FNRec;
-
- CONST
- UseMainFile : boolean = true;
- UnGetFlag : boolean = false;
- IdChar : CharSet = ['a'..'z', 'A'..'Z', '_', '^'];
- IdNum : CharSet = ['0'..'9'];
- Listing : boolean = true;
- MaxPageLine : integer = 52;
-
- VAR
- MainFileName : STRING;
- IncludeFileName : STRING;
- MainFile : FileType;
- IncludeFile : FileType;
- FileName : STRING;
-
- SaveCh,
- ch : char;
- SavePntr,
- Pntr : integer;
- SaveInStg,
- InStg : InStgType;
- SaveEndOfLine,
- EndOfLine : boolean;
-
- outfile : text;
- LineNumber : integer;
- PageNumber : integer;
- PageLine : integer;
- id : IdStgType;
- outstg : string[132];
- Nu : integer; (* current number of line numbers per line *)
- DateTime : DTstgType;
-
- Xref : IndexFile;
- LastNode : NodeType;
- NextNode : Nodetype;
- OldLastNode: NodeType;
- FirstNode : FirstNodeType;
- Nptr : integer;
- FreeNptr : integer;
-
- PROCEDURE IsTextFile (FName : STRING);
-
- VAR
- InFile : FILE OF BYTE;
- EOF : BYTE;
- IORes : WORD;
-
- BEGIN
- ASSIGN(InFile,FName);
- {$I-} RESET(InFile); {$I+}
- IORes := IORESULT;
- IF IORes <> 0 THEN BEGIN
- WRITELN('Problem # ',IORes,' opening File: ',FName);
- HALT(100);
- END;
- SEEK(InFile,FILESIZE(Infile)-1);
- READ(InFile,EOF);
- IF NOT (EOF = ORD(^Z)) THEN BEGIN
- WRITELN(^G);
- WRITELN('-- "',FName, '" --');
- WRITELN('doesn''t appear to be a text file and');
- WRITELN('doesn''t terminate with a ^Z and cannot be processed by Xref.');
- WRITELN;
- WRITELN('Try adding a Ctrl-Z to the end of the file, if it is a text file.');
- WRITELN('Xref program aborted. (ERRORLEVEL = 4)');
- WRITELN;
- CLOSE(OutFile);
- HALT(4);
- END;
- CLOSE(InFile);
- END;
-
- {.pa}
- {----------------------------------------------------------------}
-
- Procedure InitResvWords;
- CONST
- NumRwd = 48;
-
- TYPE
- RwdType = array [1..2,1..NumRwd] of String[9];
-
- Const
- Rwd : RwdType = (
- ('ABSOLUTE','AND','ARRAY','BEGIN','CASE','CONST','DIV',
- 'DO','DOWNTO','ELSE','END','EXTERNAL','FILE','FOR',
- 'FORWARD','FUNCTION','GOTO','IF','IMPLEMENTATION','IN',
- 'INLINE','INTERFACE','INTERRUPT','LABEL',
- 'MOD','NIL','NOT','OF','OR','PACKED','PROCEDURE',
- 'PROGRAM','RECORD','REPEAT','SET','SHL','SHR','STRING',
- 'THEN','TO','TYPE','UNIT',
- 'UNTIL','USES','VAR','WHILE','WITH','XOR'),
-
- ('AND','ARRAY','BEGIN','BREAK','CASE','CONST','CYCLE','DIV',
- 'DO','DOWNTO','ELSE','END','EXTERN','FILE','FOR',
- 'FORWARD','FUNCTION','GOTO','IF','IMPLEMENTATION','IN',
- 'INTERFACE','LABEL','LSTRING','MOD','MODULE','NIL',
- 'NOT','OF','OR','ORIGIN','OTHERWISE','PACKED','PROCEDURE',
- 'PROGRAM','RECORD','REPEAT','SET',
- 'THEN','TO','TYPE','UNIT',
- 'UNTIL','USES','VAR','WHILE','WITH','XOR'));
-
- var
- loop : integer;
-
- begin
- for loop := 1 to NumRwd do
- IF Rwd[LangType,Loop] <> '' THEN BEGIN
- Nptr := FreeNptr;
- FreeNptr := FreeNptr + 1;
- New (LastNode);
- FirstNode [Nptr].Last := LastNode;
- FirstNode [Nptr].Next := LastNode;
- LastNode^.data := -10;
- LastNode^.Next := nil;
- AddKey (Xref, Nptr, Rwd [LangType,loop]);
- if Not TreeOK then writeln ('error InitResvWords '+Rwd [LangType,loop]);
- end;
- end;
-
- {.pa}
- {----------------------------------------------------------------}
-
- Procedure InitStdIds;
- CONST
- NumStd = 154;
-
- TYPE
- StdType = array [1..2,1..NumStd] of String[29];
-
- Const
- Std : StdType = (
- ('ABS','ADDR','APPEND','ARCTAN','ASSIGN',
- 'BLACK','BLINK','BLUE','BLOCKREAD',
- 'BLOCKWRITE','BOOLEAN','BROWN','BW40','BW80',
- 'BYTE','C40','C80','CHAR','CHDIR','CHR','CLOSE',
- 'CLREOL','CLRSCR','CONCAT','COPY','COS','CRT','CSEG','CYAN',
- 'DARKGRAY','DEC','DELLINE','DELAY','DELETE','DISPOSE','DOS',
- 'DSEG','EOF','EOLN','ENVCOUNT','ERASE','EXEC',
- 'EXIT','EXITMODE','EXITPROC','EXP',
- 'FALSE','FILEMODE','FILEPOS','FILESIZE','FILLCHAR','FLUSH','FRAC',
- 'FREEMEM','GETDIR','GETMEM','GOTOXY','GRAPH','GREEN','HALT',
- 'HEAPPTR','HI','IORESULT','INC',
- 'INPUT','INSLINE','INSERT','INT','INTEGER','INTR',
- 'KEYPRESSED','LENGTH','LIGHTBLUE','LIGHTCYAN','LIGHTGRAY',
- 'LIGHTGREEN','LIGHTMAGENTA','LIGHTRED','LN','LO',
- 'LONGINT','LOWVIDEO','LST',
- 'MAGENTA','MARK','MAXAVAIL','MAXINT','MEM',
- 'MEMAVAIL','MEMW','MKDIR','MOVE','MSDOS','NEW',
- 'NORMVIDEO','NOSOUND','ODD','OFS','ORD','OVRPATH',
- 'OUTPUT','OVERLAY','PARAMCOUNT','PARAMSTR','PI',
- 'PORT','PORTW','POS','PRED','PREFIXSEG','PRINTER',
- 'PTR','RANDOM','RANDOMIZE',
- 'READ','READKEY','READLN','REAL','RED','RELEASE','RENAME','RESET',
- 'REWRITE','RMDIR','ROUND','SEEK','SEEKEOF','SEEKEOLN',
- 'SEG','SIN','SIZEOF','SOUND','SQR','SQRT','SSEG','STR',
- 'SUCC','SWAP','TEXT','TEXTBACKGROUND','TEXTCOLOR',
- 'TEXTMODE','TRUE','TRUNC','TRUNCATE','UPCASE',
- 'VAL','WHEREX','WHEREY','WHITE','WORD',
- 'WRITE','WRITELN','YELLOW'),
-
- ('ABORT','ABS','ADR','ADS','APPEND','ARCTAN','ASSIGN',
- 'BOOLEAN','BYTE','CHAR','CHR','CLOSE',
- 'CONCAT','COPY','COPYLST','COPYSTR','COS',
- 'DATE','DECODE','DELETE','DISPOSE','ENCODE',
- 'EOF','EOLN','EVAL','EXP','FALSE','FILLC','FILLCS',
- 'FREECT','GET','HIBYTE','HIWORD',
- 'INPUT','INSERT','INTEGER','INTEGER4',
- 'LN','LOBYTE','LOWER','LOWORD','MARK','MAXINT',
- 'MEMAVL','MOVEL','MOVER','MOVESL','MOVESR','NEW',
- 'ODD','ORD','OUTPUT','PAGE','POSITN','PRED','PUT',
- 'READ','READLN','REAL','REAL8','RELEAS','RESET','RESULT',
- 'RETURN','RETYPE','REWRITE','ROUND','SCANEQ','SCANNE',
- 'SEEK','SIN','SIZEOF','SQR','SQRT',
- 'SUCC','TEXT','TIME','TRUE','TRUNC','UPPER',
- 'WORD','WRITE','WRITELN','WRD',
- '','','','','','','','','','','','','','','','','','','',
- '','','','','','','','','','','','','','','','','','','',
- '','','','','','','','','','','','','','','','','','','',
- '','','','','','','','','','','','',''));
- var
- loop : integer;
-
- begin
- for loop := 1 to NumStd do
- IF Std[LangType,Loop] <> '' THEN BEGIN
- Nptr := FreeNptr;
- FreeNptr := FreeNptr + 1;
- New (LastNode);
- FirstNode [Nptr].Last := LastNode;
- FirstNode [Nptr].Next := LastNode;
- LastNode^.data := -20;
- LastNode^.Next := nil;
- AddKey (Xref, Nptr, Std [LangType,loop]);
- if Not TreeOK then writeln ('error InitStdIds '+Std [LangType,loop]);
- end;
- end;
-
- {.pa}
- {----------------------------------------------------------------}
-
- PROCEDURE GetFileDate (Name : STRING);
- BEGIN
-
- FileDateAndTime := GetFileDateAndTimeString (Name);
-
- END;
-
- {.pa}
- {----------------------------------------------------------------}
-
- PROCEDURE NewPage;
- VAR
- Loop : INTEGER;
- BEGIN
- IF Footing <> '' THEN BEGIN
- FOR Loop := PageLine TO MaxPageLine DO
- WRITELN (OutFile);
- WRITELN (OutFile, Footing);
- END;
-
- PageLine := 1;
- PageNumber := PageNumber + 1;
- WRITE (outfile, ff);
-
- WRITELN (outfile, 'PASCAL XRef V'+Ver+
- ' Copyright (c) 1989 by DML Software Inc.'+
- ' Date: '+ Today+
- ' Page '+I2S(PageNumber,'###@'));
-
-
- WRITE (outfile, 'Main File: '+MainFileName+' <', MainFileDateAndTime, '>');
-
- IF MainFileName <> FileName THEN BEGIN
- WRITELN (outfile,' Include File: '+FileName+' <', FileDateAndTime, '>');
- END
- ELSE
- WRITELN (outfile);
-
- writeln (outfile);
- WRITELN (OutFile, Heading);
- writeln (outfile);
- end;
-
- {.pa}
- {----------------------------------------------------------------}
-
- Procedure UnGetChar;
- begin
- UnGetFlag := true;
- end;
-
- {.pa}
- {----------------------------------------------------------------}
-
- Function GetCharFrom (var InFile : FileType) : char;
- VAR
- RecCount : INTEGER;
-
- PROCEDURE DoBlockRead;
- BEGIN
- pntr := 0;
- FILLCHAR(InStg,MaxSec,#0);
- BlockRead (infile, instg, Sec, RecCount);
- END;
-
- begin
- if UnGetFlag then begin
- UnGetFlag := false;
- GetCharFrom := UpCase(ch);
- end
- else if not Listing then begin
- if pntr >= MaxSec then DoBlockRead;
- pntr := pntr + 1;
- ch := instg [pntr];
- if ch = chr (13) then begin
- pntr := pntr + 1;
- ch := ' ';
- end;
- if ch = chr (26) then
- ch := chr (0); (* end of file *)
- GetCharFrom := UpCase (ch);
- end
- else begin
- if EndOfLine then begin
- LineNumber := LineNumber + 1;
- EndOfLine := false;
- write (outfile, RJS(I2S(LineNumber,'####@'), Margin+5) + ' ');
- end;
-
- if pntr >= MaxSec then DoBlockRead;
-
- pntr := pntr + 1;
- ch := instg [pntr];
-
- if ch = chr(13) then begin
- EndOfLine := true;
- pntr := pntr + 1; (* skip linefeed char *)
- ch := ' ';
- end
- else if ch = chr(26) then begin
- EndOfLine := TRUE;
- ch := chr (0); (* set end of file *)
- end;
-
- GetCharFrom := UpCase (ch);
-
- outstg := outstg + ch;
- if EndOfLine then begin
- writeln (outfile, outstg);
- WRITE; { allow Ctrl-Break to work }
- outstg := '';
- PageLine := PageLine + 1;
- if PageLine > MaxPageLine then
- NewPage;
- end;
- end;
- end;
-
- {.pa}
- {----------------------------------------------------------------}
-
- Function GetChar : char;
- begin
- if UseMainFile then
- GetChar := GetCharFrom (MainFile)
- else
- GetChar := GetCharFrom (IncludeFile);
- end;
-
- {.pa}
- {-------------------------------------------------------------}
-
- Procedure OpenInputFile (Filename : IDstgType; var InFile : FileType );
-
- var
- OpenErrNum : integer;
- OpenOk : boolean;
-
- begin
- IsTextFile (FileName);
- GetFileDate (FileName);
- assign(InFile, FileName );
- {$I-} reset(InFile,RecLen); {$I+}
- OpenErrNum := IOresult;
- EndOfLine := False;
- OpenOK := ( OpenErrNum = 0 );
- if not OpenOK then
- writeln ('*** Input Open Error #', OpenErrNum );
-
- end;
-
- {.pa}
- {-------------------------------------------------------------}
-
- Procedure ChangeBack;
- begin
- UseMainFile := True;
- DEC(IncCount);
- Close (IncludeFile);
- ch := SaveCh;
- Pntr := SavePntr;
- Instg := SaveInstg;
- EndOfLine := SaveEndOfLine;
- FileName := MainFileName;
- FileDateAndTime := '';
- NewPage;
- LineNumber := LineNumber + 1;
- write (outfile, RJS(I2S(LineNumber,'####@'), Margin+5) + ' ');
- end;
-
- {.pa}
- {-------------------------------------------------------------}
-
- Procedure FileChange;
- begin
- OpenInputFile (IncludeFileName, IncludeFile);
- UseMainFile := False;
- SaveCh := ch;
- SavePntr := Pntr;
- SaveInstg := Instg;
- SaveEndOfLine := EndOfLine;
- FileName := IncludeFileName;
- NewPage;
- Pntr := MaxSec;
- EndOfLine := false;
- LineNumber := LineNumber + 1;
- write (outfile, RJS(I2S(LineNumber,'####@'), Margin+5) + ' ');
- end;
-
- {.pa}
- {------Function GetId-----------------------------------------}
-
- Function GetNextInteger : integer;
- var
- temp : String [5];
-
- begin
- temp := '';
- ch := GetChar;
- while ch = ' ' do
- ch := GetChar;
- While (ch in ['0'..'9']) and (length (temp) < 5) do begin
- temp := temp + ch;
- ch := GetChar;
- end;
- GetNextInteger := S2I (Temp);
- end;
-
- {.pa}
- {-------------------------------------------------------------}
- FUNCTION GetTitleLine : STRING;
- VAR
- Temp : STRING;
- Loop : INTEGER;
- Done : BOOLEAN;
- BEGIN
- Temp := '';
- REPEAT
- Temp := Temp + GetChar;
- UNTIL EndOfLine;
-
- Done := FALSE;
- Loop := LENGTH (Temp);
- REPEAT
- IF Temp [Loop] = '}' THEN BEGIN
- Done := TRUE;
- Temp := COPY (Temp, 1, Loop - 1);
- END
- ELSE IF Temp [Loop] = ')' THEN BEGIN
- Done := TRUE;
- Temp := COPY (Temp, 1, Loop - 2);
- END
- ELSE BEGIN
- Loop := Loop - 1;
- Done := Loop = 0;
- END;
- UNTIL Done;
- GetTitleLine := Temp;
- END;
-
- {.pa}
- {-------------------------------------------------------------}
-
- {------Function GetId-----------------------------------------}
-
- Function GetId : IdStgType;
- var
- temp : string[255];
-
- {.pa}
-
- {------Function GetId-----------------------------------------}
-
- Procedure SetMargin;
- begin
- if Listing then begin
- Margin := GetNextInteger;
- end;
- end;
-
- {.pa}
- {------Function GetId-----------------------------------------}
-
- Procedure PageBreak;
- begin
- if Listing then begin
- repeat
- ch := GetChar;
- until EndOfLine;
- NewPage;
- end;
- end;
-
- {.pa}
- {------Function GetId-----------------------------------------}
-
- Procedure NewPageIfSpace;
- begin
- if Listing then begin
- IF (MaxPageLine - PageLine) < GetNextInteger THEN PageBreak;
- end;
- end;
-
- {.pa}
- {------Function GetId-----------------------------------------}
-
- Procedure SetHeading;
- begin
- if Listing then begin
- Heading := GetTitleLine;
- end;
- end;
-
- {.pa}
- {------Function GetId-----------------------------------------}
-
- Procedure SetFooting;
- begin
- if Listing then begin
- Footing := GetTitleLine;
- end;
- end;
-
-
- {.pa}
- {------Function GetId-----------------------------------------}
-
- Procedure SetPageLength;
- begin
- if Listing then begin
- MaxPageLine := GetNextInteger;
- end;
- end;
-
- {.pa}
-
- Procedure Directive;
- VAR
- Include : BOOLEAN;
- begin
- Include := FALSE;
- ch := GetChar;
- if ch in ['i', 'I'] then begin
- ch := GetChar;
- IF LangType = 1 THEN { Turbo }
- if NOT (ch IN ['-','+']) then begin
- Include := TRUE;
- while ch = ' ' do ch := GetChar;
- END
- ELSE
- ELSE { Microsoft }
- if ch IN ['N','n'] THEN BEGIN
- Include := TRUE;
- while ch <> '''' do ch := GetChar;
- ch := GetChar;
- END;
- IF Include AND KbdScrollLockStatus THEN BEGIN
- IncludeFileName := '';
- while not (ch in ['''',' ', '*', '}', ',']) do begin
- IncludeFileName := IncludeFileName + ch;
- ch := GetChar;
- end;
- INC(IncCount);
- IF IncCount > 1 THEN BEGIN
- WRITELN(^G);
- WRITELN('-- "',IncludeFileName, '" --');
- WRITELN('is nested too deeply');
- WRITELN('Xref program aborted. (ERRORLEVEL = 5)');
- WRITELN;
- CLOSE(OutFile);
- HALT(5);
- END;
- While not EndOfLine do ch := GetChar;
- FileChange;
- end
-
- else (* not an include *)
- while not EndOfLine do Ch := GetChar;
- end
- else (* not an include *)
- while not EndOfLine do ch := GetChar;
- end;
-
- {.pa}
- {------Function GetId-----------------------------------------}
-
- Procedure DotCommand;
- begin
- ch := GetChar;
- case ch of
- 'p', 'P' : begin
- ch := GetChar;
- case ch of
- 'l', 'L' : SetPageLength;
- 'a', 'A' : PageBreak;
- 'o', 'O' : SetMargin;
- else;
- end; (* case *)
- end;
- 'c', 'C' : begin
- ch := GetChar;
- case ch of
- 'p', 'P' : NewPageIfSpace;
- else;
- end; (* case *)
- end;
- 'h', 'H' : begin
- ch := GetChar;
- case ch of
- 'e', 'E' : SetHeading;
- else;
- end; (* case *)
- end;
- 'f', 'F' : begin
- ch := GetChar;
- case ch of
- 'o', 'O' : SetFooting;
- else;
- end; (* case *)
- end;
- 'l', 'L' : begin
- ch := GetChar;
- case ch of
- '-' : begin
- Repeat
- ch := GetChar;
- until EndOfLine;
- Listing := false;
- end;
- '+' : begin
- ch := GetChar;
- ch := GetChar;
- Listing := true;
- while Not EndOfLine do
- ch := GetChar;
- end;
- else;
- end; (* case *)
- end;
- else;
- end; (* case *)
- end;
-
- {.pa}
- {------Function GetId-----------------------------------------}
-
- Procedure ParseComment;
- var
- flag : boolean;
-
- begin
- ch := GetChar;
- case ch of
- '.' : DotCommand;
-
- '$' : If Listing then Directive;
-
- else begin
- flag := true;
- while (ch <> #0) and (ch <> '}') and flag do begin
- ch := getchar;
- if ch = '*' then begin
- ch := GetChar;
- if ch = ')' then
- flag := false;
- end;
- end;
- end;
- end; (* case *)
- end;
-
- {.pa}
- {------Function GetId------- RECURSIVE MEMORY HOG ------------}
-
- begin
- ch := GetChar;
- while (ch <> #0) and
- (not (ch in IdChar)) and
- (ch <> '{') and
- (ch <> '$') and
- (ch <> '(') and
- (ch <> '''') do
- ch := GetChar;
-
- case ch of
-
- #0 : begin (* end of file *)
- if UseMainFile then
- GetId := '$$eof$$'
- else begin
- ChangeBack;
- GetId := GetId; { Not an ID, try again }
- end;
- end;
-
- '''' : begin (* quoted literal *)
- ch := GetChar;
- while (ch <> #0) and (ch <> '''') do
- ch := GetChar;
- GetId := '$$FAIL$$'; { Avoid heavy recurssive loop for GetId }
- end; { when doing initialized constant arrays }
-
- '{' : begin (* easy comment *)
- ParseComment;
- GetId := GetId; { Not an ID, try again }
- end;
-
- '(' : begin (* Not so easy comment *)
- ch := GetChar;
- if ch = '*' then begin
- ParseComment;
- GetId := GetId; { Not an ID, try again }
- end
- else begin
- UnGetChar;
- GetId := GetId; { Not an ID, try again }
- end;
- end;
-
- '$' : begin (* Hex number *)
- ch := GetChar;
- while (ch <> #0) and
- (ch in ['0'..'9', 'a'..'f', 'A'..'F']) do
- ch := GetChar;
- GetId := GetId; { Not an ID, try again }
- end;
-
- else begin { An Indentifer }
- temp := '';
- while (ch <> chr (0)) and
- ((ch in IdChar) or (ch in IdNum)) do begin
- temp := temp + ch;
- ch := GetChar;
- end;
- GetId := copy (temp, 1, MaxIdLen);
- end;
- end; (* case *)
-
- end;
-
- {.pa}
- {-------------------------------------------------------------}
-
- Procedure MakeTable;
- begin
- repeat
- repeat
- REPEAT
- Id := GetId;
- UNTIL Id <> '$$FAIL$$'; { Avoid heavy recursive loop for init const arrays }
- Until (Listing) or (Id = '$$eof$$'); { Don't add IDs to table unless list on }
- FindKey (Xref, Nptr, Id);
- if TreeOK then begin
- New (LastNode);
- OldLastNode := FirstNode [Nptr].Last;
- OldLastNode^.Next := LastNode;
- FirstNode [Nptr].Last := LastNode;
- LastNode^.Data := LineNumber;
- LastNode^.Next := nil;
- end
- else begin
- Nptr := FreeNptr;
- FreeNptr := FreeNptr + 1;
- New (LastNode);
- FirstNode [Nptr].Last := LastNode;
- FirstNode [Nptr].Next := LastNode;
- LastNode^.Data := LineNumber;
- LastNode^.Next := nil;
- AddKey (Xref, Nptr, Id);
- if Not TreeOK then writeln ('Error MakeTable');
- end;
- until Id = '$$eof$$';
- end;
-
- {.pa}
- {-------------------------------------------------------------}
-
- Procedure WriteId (id : IdStgType);
- const
- blnks : IdStgType = ' ';
-
- begin
- writeln (outfile);
- if PageLine >= MaxPageLine then begin
- PageLine := 1;
- NewPage;
- end;
- write (outfile, LJS('', Margin) + id + copy (blnks, 1, 30 - length (id)));
- PageLine := PageLine + 1;
- end;
-
- {.pa}
- {-------------------------------------------------------------}
- FUNCTION RefsPerLine : INTEGER;
-
- CONST
- MaxLine = 132;
-
- BEGIN
- RefsPerLine := (MaxLine - MaxIdLen - Margin) DIV NumLen;
- END;
-
-
-
- Procedure WriteNumber ( Number : integer);
- begin
- if Nu > RefsPerLine then begin { new line }
- Nu := 1;
- WriteId (' ');
- end;
- write (outfile, Number:NumLen);
- Nu := Nu + 1;
- end;
-
- {.pa}
- {-------------------------------------------------------------}
-
- Procedure ReadTable;
- begin
- Heading := 'Pascal CROSS REFERENCE';
- WRITELN (OutFile);
- NewPage;
- ClearKey (Xref);
- NextKey (xref, Nptr, Id); (* Skip $$eof$$ *)
- NextKey (xref, Nptr, Id);
- repeat
- Nu:= 1;
- NextNode := FirstNode [Nptr].Next;
- if NextNode^.Data > 0 then begin
- WriteId (id);
- while NextNode <> nil do begin
- WriteNumber (NextNode^.Data);
- NextNode := NextNode^.Next;
- end;
- end;
- NextKey (Xref, Nptr, Id);
- Until not TreeOK;
- end;
-
- {.pa}
- {-------------------------------------------------------------}
-
- Procedure ReadStdIds;
- begin
- Heading := 'Pascal STANDARD IDENTIFIERS';
- WRITELN (OutFile);
- NewPage;
- ClearKey (Xref);
- NextKey (xref, Nptr, Id); (* Skip $$eof$$ *)
- NextKey (xref, Nptr, Id);
- repeat
- Nu:= 1;
- NextNode := FirstNode [Nptr].Next;
- if NextNode^.Data = -20 then begin
- NextNode := NextNode^.Next;
- if NextNode <> nil then begin
- WriteId (id);
- while NextNode <> nil do begin
- WriteNumber (NextNode^.Data);
- NextNode := NextNode^.Next;
- end;
- end;
- end;
- NextKey (Xref, Nptr, Id);
- Until not TreeOK;
- end;
-
- {.pa}
- {-------------------------------------------------------------}
-
- Procedure ReadResvWds;
- begin
- Heading := 'Pascal RESERVED WORDS';
- WRITELN (OutFile);
- NewPage;
- ClearKey (Xref);
- NextKey (xref, Nptr, Id); (* Skip $$eof$$ *)
- NextKey (xref, Nptr, Id);
- repeat
- Nu:= 1;
- NextNode := FirstNode [Nptr].Next;
- if NextNode^.Data = -10 then begin
- NextNode := NextNode^.Next;
- if NextNode <> nil then begin
- WriteId (id);
- while NextNode <> nil do begin
- WriteNumber (NextNode^.Data);
- NextNode := NextNode^.Next;
- end;
- end;
- end;
- NextKey (Xref, Nptr, Id);
- Until not TreeOK;
- end;
-
- {.pa}
- {-------------------------------------------------------------}
-
- procedure OpenIOFiles;
- var
- LstFileName : IdStgType;
- Temp : STRING [128];
- begin
- writeln ( 'Xreference Program. Copyright (c) 1989 by DML Software Inc. V'+ver);
-
- MainFileName := '';
- LstFileName := '';
-
- IF ParamCount >= 1 THEN
- MainFileName := ParamStr(1);
- IF ParamCount >= 2 THEN
- LstFileName := ParamStr(2);
-
- Writeln('Input file: ',MainFileName);
-
- WHILE (MainFileName = '') OR (Not Exist (MainFileName)) DO BEGIN
- writeln;
- write( 'Input file ? ' );
- readln( MainFileName );
- IF MainFileName = '' THEN HALT (100);
- END;
-
- Writeln ('Output file: ',LstFileName);
-
- WHILE (LstFileName = MainFileName) OR (LstFileName = '') DO BEGIN
- writeln;
- write ('Output file name? ');
- readln (LstFileName);
- IF LstFileName = '' THEN HALT (100);
- END;
-
- assign (outfile, LstFileName);
- rewrite (outfile);
-
- end;
-
- {.pa}
- {-------------------------------------------------------------}
- PROCEDURE CheckPrinterType (VAR Compress, Normal : STRING);
-
- VAR
- PrtStr : STRING;
- PrtCh : CHAR;
-
- BEGIN
- IF ParamCount >= 3
- THEN PrtStr := ParamStr(3)
- ELSE PrtStr := '';
- IF PrtStr = ''
- THEN PrtCh := ' '
- ELSE PrtCh := UPCASE(PrtStr[1]);
- WRITELN('Printer Type: ',PrtCh);
- WHILE NOT (PrtCh IN ['L','D','I']) DO BEGIN
- WRITELN;
- WRITE('Printer Type (L)aser, (D)atasouth, (I)bm): ');
- READLN(PrtStr);
- IF PrtStr = '' THEN HALT (100);
- PrtCh := UPCASE(PrtStr[1]);
- END;
- CASE PrtCh OF
- 'L': BEGIN { LASER }
- Compress := ^[+'E'+^[+'(s0P'+^[+'(s16.6H'+^[+'(s8.5V';
- Normal := ^[+'E';
- END;
- 'D': BEGIN { Data South 180 }
- Compress := ^O+^[+'[4w'; { 4 = 17cpi}
- Normal := ^O+^[+'[2w'; { 2 = 12cpi, 0 = 10cpi }
- END;
- 'I' : BEGIN { IBM Graphics Printer }
- Compress := ^O;
- Normal := ^R;
- END;
- END;
- END;
-
- {.pa}
- {-------------------------------------------------------------}
-
- PROCEDURE CheckLangType (VAR LangType : BYTE);
-
- VAR
- LangStr : STRING;
- LangCh : CHAR;
-
- BEGIN
- IF ParamCount >= 4
- THEN LangStr := ParamStr(4)
- ELSE LangStr := '';
- IF LangStr = ''
- THEN LangCh := ' '
- ELSE LangCh := UPCASE(LangStr[1]);
- WRITELN('Language Type: ',LangCh);
- WHILE NOT (LangCh IN ['T','M']) DO BEGIN
- WRITELN;
- WRITE('Language Type (T)urbo, (M)icrosoft Pascal: ');
- READLN(LangStr);
- IF LangStr = '' THEN HALT (100);
- LangCh := UPCASE(LangStr[1]);
- END;
- CASE LangCh OF
- 'T' : LangType := 1;
- 'M' : LangType := 2;
- END;
- END;
-
- {.pa}
- {-------------------------------------------------------------}
-
- Procedure InitVariables;
- begin
- EndOfLine := false;
- LineNumber := 1;
- PageNumber := 0;
- PageLine := 1;
- outstg := '';
- pntr := MaxSec;
-
- FreeNptr := 1;
- end;
-
- {.pa}
- {-------------------------------------------------------------}
-
- Procedure main;
-
- VAR
- Seconds : REAL;
- DOSDateTime : T_DateTime;
- Compress : STRING;
- Normal : STRING;
-
- begin
- Heading := '';
- Footing := '';
- Margin := 0;
-
- { Today := GetDate + ' ' + GetTime; }
- GetDOSDateAndTime(Seconds,DOSDateTime);
- Today := Date2S(DOSDateTime,' WWW MM/DD/YY hh:mm:ss pm');
- OpenIOFiles;
- CheckPrinterType(Compress,Normal);
- CheckLangType(LangType);
- InitIndex;
- MakeIndex (Xref, 'Xref', 30, 0);
-
- InitVariables;
- InitResvWords;
- InitStdIds;
-
- writeln (outfile, Compress); { BEGIN PRINTING }
- FileName := MainFileName;
- MainFileDateAndTime := GetFileDateAndTimeString (MainFileName);
-
- OpenInputFile (MainFileName, MainFile);
-
- Writeln ('Working ...');
-
- NewPage;
- write (outfile, LineNumber:5, ' ');
-
- MakeTable;
-
- Heading := '';
- Footing := '';
-
- ReadTable;
- ReadStdIds;
- ReadResvWds;
-
- writeln (outfile, ff, normal); { END PRINTING }
-
- close (outfile);
- end;
-
- {$F+}
- PROCEDURE ProgramExit;
- BEGIN
- EXITPROC := ExitSave;
- IF (ERRORADDR <> NIL) OR (EXITCODE = 255) THEN BEGIN
- CLOSE(OutFile);
- WRITELN(^J^M,'Turbo Pascal Abend');
- END;
- END;
- {$F-}
-
- PROCEDURE ExitInit;
- BEGIN
- ExitSave := EXITPROC;
- EXITPROC := @ProgramExit;
- END;
-
- begin
- ExitInit;
- FILEMODE := 0; { Read Only }
- TEXTCOLOR(LIGHTGRAY);
- main;
- end.
-